<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!-- jQuery 2.0.2 -->
<script src="${initParam.root }/static/js/jquery.min.js"></script>
<script src="${initParam.root }/static/js/jquery-migrate-1.2.1.js"></script>
<!-- jQuery UI 1.10.3 -->
<script src="${initParam.root }/static/js/jquery-ui-1.10.3.min.js"
	type="text/javascript"></script>
<!-- Bootstrap -->
<script src="${initParam.root }/static/js/bootstrap.min.js"
	type="text/javascript"></script>
<!-- AdminLTE App -->
<script src="${initParam.root }/static/js/AdminLTE/app.js"
	type="text/javascript"></script>
<!-- Bootstrap WYSIHTML5 -->
<script
	src="${initParam.root }/static/js/plugins/html5shiv/html5shiv.js"></script>
<!-- iCheck -->
<script src="${initParam.root }/static/js/plugins/iCheck/icheck.min.js"></script>

<script
	src="${initParam.root }/static/js/plugins/respond/respond.min.js"></script>

<!-- fancybox -->
<script
	src="${initParam.root }/static/js/plugins/fancybox/jquery.fancybox-1.3.4.js"
	type="text/javascript"></script>

<script src="${initParam.root }/static/js/jquery-1.11.3.js"></script>
<script src="${initParam.root }/static/js/jquery.validate.js"></script>
<script>
	$(function() {
		/*发送邮件还是存草稿  */
		$("#send").click(function() {
			$("#isSend").val(1);
			$("#message-form").submit();
		})
		$("#drafts").click(function() {
			$("#isSend").val(0);
			$("#message-form").submit();
		});

		//显示受邀人列表
		var isOpen = false;
		$("#ycy_div_actorList").on("click", "#lbl_addAcotr", function() {
			checkOpen();
		})
		$("#i_addAcotr").click(function() {
			checkOpen();
		});
		//是否打开
		function checkOpen() {
			if (isOpen == false) {
				$("#div_actorList").slideDown();
				isOpen = true;
			} else {
				$("#div_actorList").slideUp();
				isOpen = false;
			}
		}

		//点击受邀人列表
		$(".ycy_ul_actor").click(function() {
			$(".ycy_ul_actor").next().slideUp();
			$(this).next().slideDown();
		});
		//添加受邀请人
		$(".ycy_ul_click li").click(function() {
				var id = $(this).attr("data-id");
				var name = $(this).text();
					$.ajax({
						url: "${initParam.root}/rest/receiver-add",
						data: {receiver_id:id},
						dataType: "json",
						type:"get",
						success:function(){
							if($("#creator>#creator_id").val()==""){
								$("#creator>#creator_id").val(name);
							}else{
								$("#creator>#creator_id").val($("#creator>#creator_id").val() + "," + name);
							}	
						}
					})
				}
		);
		$("#writemessage").click(function() {
			$("#creator_id").val("");
			$("#creator_id").attr("disabled",false);
			$("#title").val("");
			$("#title").attr("disabled",false);
			$("#content").val("");
			$("#content").attr("disabled",false);
		})

		$(".add-message").click(function() {
			var id = $(this).attr("ref-id");
			$.ajax({
				url:"${initParam.root}/rest/message-edit?messageId="+id,
				dataType:"json",
				success:function(Message){
					$("#creator_id").val(Message.receivers);
					$("#creator_id").attr("disabled","disabled");
					$("#title").val(Message.title);
					$("#title").attr("disabled","disabled");
					$("#content").val(Message.content);
					$("#content").attr("disabled","disabled");
					
				}
			})
		});
		
		$(".edit-message").click(function() {
			var id = $(this).attr("ref-id");
			var level = $(this).attr("data-level");
			$.ajax({
				url:"${initParam.root}/rest/message-edit?messageId="+id,
				dataType:"json",
				success:function(Message){
					$("#creator_id").val(Message.receivers);
					$("#title").val(Message.title);
					$("#content").val(Message.content);
					$('#importantId').val(level);
					
				}
			})
		});
		
	})
</script>


<!-- 模态框（Modal） -->
<div class="modal fade" id="compose-modal" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">编写邮件</h4>
			</div>
			<form action="${initParam.root }/message" method="post"
				id="message-form">
				<div class="modal-body">
					<div class="form-group" id="creator">
						<label for="exampleInputEmail1">收件人</label> <input type="text"
							class="form-control" placeholder="收件人" name="creator_id"
							id="creator_id">
					</div>
					<div class="form-group">
						<label for="inputEmail3" class="control-label">&nbsp;</label>
						<div class="col-sm-10" id="ycy_div_actorList">
							<i class="fa fa-fw fa-plus-circle" id="i_addAcotr"></i> <label
								id="lbl_addAcotr">添加收件人</label>
						</div>
					</div>
					<div id="div_actorList" class="form-group" style="display: none;">
						<label for="inputEmail3" class="col-sm-2 control-label">&nbsp;</label>
						<div style="height: 100px; overflow: auto;">
							<c:forEach var="department" items="${departmentList }">
								<span class="ycy_ul_actor">${department.name }</span>
								<ul style="list-style: none" class="ycy_ul_click">
									<c:forEach var="employee" items="${department.employeeList }">
										<li data-id="${employee.id }" id="receiver_id"><i
											class="fa fa-angle-double-right"></i>${employee.name }</li>
									</c:forEach>
								</ul>
								<hr style="border-color: rgba(0, 0, 0, 0.3);" />
							</c:forEach>
						</div>
					</div>
					<div class="form-group">
						<label for="exampleInputPassword1">标题</label> <input type="text"
							class="form-control" placeholder="标题" name="title" id="title">
					</div>
					<div class="form-group">
						<label for="exampleInputPassword1">正文</label>
						<textarea name="content" class="form-control" placeholder="正文"
							style="height: 200px; width: 550px; max-height: 200px; max-width: 550px;"
							id="content"></textarea>
					</div>
					<div class="form-group">
						<label for="exampleInputPassword1">重要级别</label> <select
							name="importantId" id="importantId">
							<option selected="selected" value="-1">请选择</option>
							<option value="1">一级</option>
							<option value="2">二级</option>
							<option value="3">三级</option>
						</select>
					</div>
					<div class="form-group">
						<label for="exampleInputFile">附件</label> <input type="file"
							id="exampleInputFile">
					</div>
					<input type="hidden" id="isSend" name="isSend">
				</div>
				<div class="modal-footer" id="drafts-send">
					<button type="button" id="send" class="btn btn-primary">发送</button>
					<button type="button" id="drafts" class="btn btn-primary">存草稿</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				</div>
			</form>
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal -->
</div>




